//
//  BKViewModel.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/5/30.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKMatchingScoreViewModel.h"
#import <AFNetworking.h>

@interface BKMatchingScoreViewModel ()
@property (nonatomic ,copy) NSDictionary *provDic;
@property (nonatomic ,copy) NSDictionary *piciDic;
@property (nonatomic ,copy) NSDictionary *typeDic;

@property (nonatomic ,strong) NSMutableArray *dataArray;

@end

@implementation BKMatchingScoreViewModel


- (id)init{

    self = [super init];
    if (self) {
        _provDic =  @{
                       @"不限":@"",
                       @"北京":@"1",
                       @"天津":@"2",
                       @"上海":@"3",
                       @"重庆":@"4",
                       @"河北":@"5",
                       @"河南":@"6",
                       @"山东":@"7",
                       @"山西":@"8",
                       @"安徽":@"9",
                       @"江西":@"10",
                       @"江苏":@"11",
                       @"浙江":@"12",
                       @"湖北":@"13",
                       @"湖南":@"14",
                       @"广东":@"15",
                       @"广西":@"16",
                       @"云南":@"17",
                       @"贵州":@"18",
                       @"四川":@"19",
                       @"陕西":@"20",
                       @"青海":@"21",
                       @"宁夏":@"22",
                       @"黑龙江":@"23",
                       @"吉林":@"24",
                       @"辽宁":@"25",
                       @"西藏":@"26",
                       @"新疆":@"27",
                       @"内蒙古":@"28",
                       @"海南":@"29",
                       @"福建":@"30",
                       @"甘肃":@"31"};
        _piciDic = @{@"提前批":@"5",
                      @"本科一批":@"11",
                      @"本科二批":@"12",
                      @"本科三批":@"13",
                      @"高职专科":@"20",
                      };
        
        _typeDic = @{@"综合":@"1",
                     @"工科":@"2",
                     @"师范":@"3",
                     @"财经":@"4",
                     @"政法":@"5",
                     @"语言":@"6",
                     @"医药":@"7",
                     @"农业":@"8",
                     @"林业":@"9",
                     @"民族":@"10",
                     @"艺术":@"11",
                     @"体育":@"12",
                     @"军事":@"13"};
        
        _dataArray = [NSMutableArray array];

    }
    return self;
}

- (void)colleageWithkq:(NSString *)kq
                    kf:(NSString *)kf
                   pwh:(NSString *)pwh
                   pwe:(NSString *)pwe
                    wl:(NSString *)wl
                    pc:(NSString *)pc
                    dp:(NSString *)dp
                    fw:(NSString *)fw
           currentPage:(NSString *)currentPage
               success:(void (^)(NSArray *))success
               failure:(void (^)(NSString *))failure{
    
    if ([currentPage intValue] == 1) {
        [_dataArray removeAllObjects];
    }
    
    
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if ([kq isKindOfClass:[NSString class]]&&[kq length]>0) {
        params[@"kq"] = _provDic[kq]?:@"";
    }
    
    if ([kf isKindOfClass:[NSString class]]&&[kf length]>0) {
         params[@"kf"] = kf;
    }
   
    if ([pwh isKindOfClass:[NSString class]]&&[pwh length]>0) {
         params[@"pwh"] = pwh;
    }
    if ([pwe isKindOfClass:[NSString class]]&&[pwe length]>0) {
        params[@"pwe"] = pwe;
    }
   
    
    if ([wl isKindOfClass:[NSString class]]&&[wl length]>0) {
        params[@"wl"] = [wl isEqualToString:@"文科"]?@1:@2;
        
    }
    if ([pc isKindOfClass:[NSString class]]&&[pc length]>0) {
        params[@"pc"] = _piciDic[pc]?:@"";
    }
    if ([dp isKindOfClass:[NSString class]]&&[dp length]>0) {
        params[@"dq"] = _provDic[dp]?:@"";
    }
    
    if ([fw isKindOfClass:[NSString class]]&&[fw length]>0) {
        params[@"fw"] = _typeDic[fw]?:@"";
    }
    
    params[@"page"] = currentPage;
    params[@"len"] = @100000;
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/mobile/kaofen3"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                
                 NSDictionary *extraData = responseDic[@"extraData"];
                 NSArray *dataArray = extraData[@"info"];
                 if ([dataArray count]==0) {
                     failure(@"已加载完成");
                 }else{
                 
                     
                     success(dataArray);
                 }
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];

    

}

+ (void)compareCol:(NSString *)col success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure
{
    NSDictionary *    params = @{@"col":col};
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/mobile/cduibi"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 
                 NSArray *dataArray = responseDic[@"extraData"];
                 
                 
                 success(dataArray);
                 
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];
    

    

}
@end
